<article class="" id="post-">
<header class="entry-header">
<h1 class="entry-title">deferred.pipe()</h1>
<div class="entry-meta">
						所属分类：<span class="category"><a href="/category/deferred-object/">延迟对象</a></span><span class="category-divider"> | </span><span class="category"><a href="/category/deprecated/">弃用</a> &gt; <a href="/category/deprecated/deprecated-1.8/">1.8 版本弃用的 API</a></span>
<span class="pull-right">英文文档：<a href="https://api.jquery123.com/deferred.pipe/" target="_blank">deferred.pipe()</a></span>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<!-- .entry-header -->
<div class="entry-content">
<article class="entry method" id="deferred-pipe1"><h2 class="section-title">
<span class="name">deferred.pipe(  [doneFilter ] [, failFilter ] )</span><span class="returns">返回: <a href="/Types/#Promise">Promise</a></span><span class="version-details">version deprecated: <a href="/category/version/1.8/">1.8</a></span>
</h2>
<div class="entry-wrapper">
<p class="desc"><strong>描述: </strong> 用用于过滤 and/or 链式延迟对象的工具方法。 </p>
<ul class="signatures">
<li class="signature" id="deferred-pipe-doneFilter-failFilter">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.6/">1.6</a></span>deferred.pipe(  [doneFilter ] [, failFilter ] )</h4>
<ul>
<li>
<div><strong>doneFilter</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        一个函数，或者函数数组，当Deferred（延迟）对象得到解决时被调用。
			      </div>
</li>
<li>
<div><strong>failFilter</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        可选的 一个函数，或者函数数组，当Deferred（延迟）对象拒绝时被调用。
			      </div>
</li>
</ul>
</li>
<li class="signature" id="deferred-pipe-doneFilter-failFilter-progressFilter">
<h4 class="name">
<span class="version-details">添加的版本: <a href="/category/version/1.7/">1.7</a></span>deferred.pipe(  [doneFilter ] [, failFilter ] [, progressFilter ] )</h4>
<ul>
<li>
<div><strong>doneFilter</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        一个函数，或者函数数组，当Deferred（延迟）对象得到解决时被调用。
			      </div>
</li>
<li>
<div><strong>failFilter</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        一个函数，或者函数数组，当Deferred（延迟）对象得到拒绝时被调用。
			      </div>
</li>
<li>
<div><strong>progressFilter</strong></div>
<div>类型: <a href="/Types/#Function">Function</a>()</div>
<div>
			        一个可选的函数，当进度通知发送给Deferred（延迟）被调用。
			      </div>
</li>
</ul>
</li>
</ul>
<div class="longdesc" id="entry-longdesc">
<p><strong>Deprecation Notice:（推荐使用的注意事项：）</strong>从jQuery 1.8开始,  deferred.pipe() 方法过时. 应该使用<code>deferred.then()</code> 代替它。</p>
<p><code>deferred.pipe()</code>方法返回一个新的promise（允诺），用于过滤状态或通过函数返回的延迟对象的值。<code>doneFilter</code>和<code>failFilter</code>函数过滤原先deferred（延迟）的解决/拒绝的状态和值。<strong>从 jQuery 1.7开始</strong>,该方法还接受一个<code>progressFilter</code>函数，用来过滤任何访问deferred（延迟）的<code>notify</code>或<code>notifyWith</code> 方法。这些过滤器可以随着 pipe promise 的 <code>done()</code>或<code>fail()</code> 回调函数的调用，返回一个新值，或返回其它可见对象(Deferred, Promise, 等等)，这些可见对象传递了自身的解决（resolve) / 拒绝(reject)状态和传递给 pipe promise 回调函数的值。如果将 <code>null</code>  作为过滤函数，或者不指定过滤函数，那么 pipe promise 被受理（resolve)或被拒绝(reject)时，会使用相同的值作为原始值。</p>
</div>
<section class="entry-examples" id="entry-examples"><header><h2 class="underline">例子:</h2></header><div class="entry-example" id="example-0">
<h4>Example: <span class="desc"> 过滤解决值:</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">var</span> defer = $.Deferred(),</code></div></div><div class="container"><div class="line"><code>    filtered = defer.pipe(<span class="keyword">function</span>( value ) {</code></div></div><div class="container"><div class="line"><code>      <span class="keyword">return</span> value * <span class="number">2</span>;</code></div></div><div class="container"><div class="line"><code>    });</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>defer.resolve( <span class="number">5</span> );</code></div></div><div class="container"><div class="line"><code>filtered.done(<span class="keyword">function</span>( value ) {</code></div></div><div class="container"><div class="line"><code>  alert( <span class="string">"Value is ( 2*5 = ) 10: "</span> + value );</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-1">
<h4>Example: <span class="desc">过滤拒绝值:</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">var</span> defer = $.Deferred(),</code></div></div><div class="container"><div class="line"><code>    filtered = defer.pipe( <span class="literal">null</span>, <span class="keyword">function</span>( value ) {</code></div></div><div class="container"><div class="line"><code>      <span class="keyword">return</span> value * <span class="number">3</span>;</code></div></div><div class="container"><div class="line"><code>    });</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>defer.reject( <span class="number">6</span> );</code></div></div><div class="container"><div class="line"><code>filtered.fail(<span class="keyword">function</span>( value ) {</code></div></div><div class="container"><div class="line"><code>  alert( <span class="string">"Value is ( 3*6 = ) 18: "</span> + value );</code></div></div><div class="container"><div class="line"><code>});</code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="entry-example" id="example-2">
<h4>Example: <span class="desc">链任务:</span>
</h4>
<div class="syntaxhighlighter javascript ">
<table>
<tbody>
<tr>
<td class="gutter">
<div class="line n1">1</div>
<div class="line n2">2</div>
<div class="line n3">3</div>
<div class="line n4">4</div>
<div class="line n5">5</div>
<div class="line n6">6</div>
<div class="line n7">7</div>
<div class="line n8">8</div>
<div class="line n9">9</div>
</td>
<td class="code">
<pre><div class="container"><div class="line"><code><span class="keyword">var</span> request = $.ajax( url, { dataType: <span class="string">"json"</span> } ),</code></div></div><div class="container"><div class="line"><code>    chained = request.pipe(<span class="keyword">function</span>( data ) {</code></div></div><div class="container"><div class="line"><code>      <span class="keyword">return</span> $.ajax( url2, { data: { user: data.userId } } );</code></div></div><div class="container"><div class="line"><code>    });</code></div></div><div class="container"><div class="line"><code> </code></div></div><div class="container"><div class="line"><code>chained.done(<span class="keyword">function</span>( data ) {</code></div></div><div class="container"><div class="line"><code>  <span class="comment">// data retrieved from url2 as provided by the first request</span></code></div></div><div class="container"><div class="line"><code>});</code></div></div><div class="container"><div class="line"><code> </code></div></div></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div></section>
</div></article> </div>
</article>